﻿using XinLife.Application.Interface;
using XinLife.Model;
using Microsoft.AspNetCore.Mvc;
using XinLife.Core.Model;

namespace XinLife.Controllers.Admin
{
    /// <summary>
    /// 角色管理
    /// </summary>
    public class RoleController : BaseController
    {
        private IRoleService _roleService;
        public RoleController(IRoleService roleService)
        {
            _roleService = roleService;
        }
        /// <summary>
        /// 获取角色列表
        /// </summary>
        [HttpGet]
        public async Task<object> GetRolePageList([FromQuery] Pagination pagination, [FromQuery] string queryJson = null)
        {
            return await _roleService.GetRolePageList(pagination, queryJson);
        }
        /// <summary>
        /// 获取角色信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<AjaxResult> GetRoleById(string id)
        {
            return await _roleService.GetRoleByIdAsync(id);
        }

        /// <summary>
        /// 修改角色
        /// </summary>-
        /// <returns></returns>
        [HttpPost]
        public async Task<AjaxResult> EditRole([FromForm] Role role)
        {
            return await _roleService.EditRoleAsync(role);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        [HttpPost]
        public async Task<AjaxResult> DelRole([FromForm] string ids)
        {
            return await _roleService.DelRoleAsync(ids);
        }

        /// <summary>
        /// 获取当前角色的权限
        /// </summary>
        [HttpGet]
        public async Task<AjaxResult> GetRoleAuthList(string roleId)
        {
            return await _roleService.GetRoleAuthListAsync(roleId);
        }

        /// <summary>
        /// 保存角色
        /// </summary>
        [HttpPost]
        public async Task<AjaxResult> SaveRoleAuth([FromForm] RoleAuthInputDto roleAuthInputDto)
        {
            return await _roleService.SaveRoleAuth(roleAuthInputDto);
        }

        /// <summary>
        /// 获取角色列表-key-value
        /// </summary>
        [HttpGet]
        public async Task<AjaxResult> GetRoleList()
        {
            var data = await _roleService.GetRoleList();

            return Success(data);
        }
    }
}
